package LOGISTICS.U8PickUp;
import java.net.InetAddress;
import java.net.UnknownHostException;

import javax.swing.JFrame;
import javax.swing.WindowConstants;

import TOOLS.SQLtool;

public class test001_newDB {

	public static void main(String[] args) {
		SQLtool sql=new SQLtool();
		String IPaddr="192.168.1.1";
		try {
			InetAddress addr = InetAddress.getLocalHost();
			IPaddr=addr.getHostAddress();
		} catch (UnknownHostException e1) {
			;
		}
//		sql.config(IPaddr, "AKS2019", "sa", "123456","testNewDB");
		sql.config("192.168.0.39", "AKS2019", "sa", "abcd1234!","testNewDB");
		try {
			JFrame j=new JFrame();
			j.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
			j.setVisible(true);
			j.setLocation(-800, 0);
			sql.connect();
			
			String tableName="[QM].[history_laserCheck]";
			String sqlStr="IF OBJECT_ID('"+tableName+"', 'U') IS NOT NULL DROP TABLE "+tableName;
			tableName="[dbo].[U8pickUpInfo]";
			sqlStr="IF OBJECT_ID('"+tableName+"', 'U') IS NOT NULL DROP TABLE "+tableName;
			try {
				sql.Command(sqlStr);
			} catch (Exception e) {
				if(e.getMessage().equals("-11")) {
					;
				}else {
					throw e;
				}
			}
			sqlStr="CREATE TABLE "+tableName+" (\r\n" + 
					"[U8pickUpInfoIndex] int IDENTITY(1,1) NOT NULL UNIQUE,\r\n" + 
					"[state] int DEFAULT 1,\r\n" + 
					"[orderNumber] varchar(150) NOT NULL,\r\n" + 
					"[partNumber] varchar(150) NULL,\r\n" + 
					"[targetPartNumber] varchar(150) NULL,\r\n" + 
					"[planQty] int DEFAULT 0,\r\n" + 
					"[quantity] int DEFAULT 0,\r\n" + 
					"[tips] varchar(150) NULL,\r\n" + 
					"[createTime] datetime DEFAULT GETDATE(),\r\n" + 
					"[lastTime] datetime DEFAULT GETDATE() \r\n" + 
					")";
			sql.Command(sqlStr);
			
			
			j.dispose();
			System.exit(0);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
